package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 分页查询菜品
     * @param dto
     * @return
     */
    Page<DishVO> selectPage(DishPageQueryDTO dto);

    /**
     * 根据id找出正在销售中的菜品
     * @param idSqlList
     * @return
     */
    int selectCountOnSellByIds(String idSqlList);

    /**
     * 根据id删除菜品
     * @param dishIds
     */
    @Delete("delete from dish where id in (#{dishIds})")
    void deleteByIds(String dishIds);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish selectById(Long id);

    /**
     * 根据id更新菜品
     * @param dish
     */
    void update(Dish dish);

    /**
     * 条件查询
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);
}
